<?php
/**
 * This file is part from Ewuroweb Shop
 *
 * @package 
 * @author Ivan I. Atanasov <i.atanasov@viscomp.bg>
 */

class EW_Validate_PasswordConfirmation extends Zend_Validate_Abstract
{
    const NOT_MATCH = 'notMatch';
 
    /**
     * Confirm Field Name
     * 
     * @var string
     * @access private
     */
    private $_confirmField = '';
    
    protected $_messageTemplates = array(
        self::NOT_MATCH => 'Password confirmation does not match'
    );
 
    public function __construct($params) {
        $this->_confirmField = $params['confirmField'];
    }
    
    public function isValid($value, $context = null)
    {
        $value = (string) $value;
        $this->_setValue($value);
 
        if (is_array($context)) {
            if (isset($context[$this->_confirmField])
                && ($value == $context[$this->_confirmField]))
            {
                return true;
            }
        } elseif (is_string($context) && ($value == $context)) {
            return true;
        }
 
        $this->_error(self::NOT_MATCH);
        return false;
    }
}